home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.08 Aug 94 / About Box tip next >
Encoding:
Text File  |  1994-07-18  |  2.6 KB  |  42 lines  |  [TEXT/MPS ]

  1. TCL 2.0 Startup Splash Screen
  2. Version 2.0 of the TCL introduced a new method in CApplication called ShowSplashScreen().  This method is called at startup in  CApplication::DoRun(), prior to the program handling any AppleEvents.  Although the Visual Architect can be used to create the code  neccessary for a splash screen, it is much simpler for you to write  your own by hand, especially if all you want to do is display a PICT  resource for a number of seconds.  This is especially true if you  want to add a splash screen to projects you are converting from 1.1.3.
  3. To use the code below, override ShowSplashScreen()  in your own CApplication derived class, and then make sure the source file contains all of the code outlined below.  Features of the code are: TCL 2.0 use of constructors with default arguments; moving the window offscreen prior to calling Select() & Prepare(), thus preventing the user at staring at a blank window  for a second before the CPicture object can be drawn; ‘paranoid’ memory cleanup to make absolutely certain there are no memory leaks.
  4. //    TCL INCLUDES…
  5. #include   <CDecorator.h>
  6. #include   <CPicture.h>
  7. #include   <CWindow.h>
  8. //    EXTERN GLOBALS…
  9. extern   CDecorator   *gDecorator;
  10.  
  11. void myCApplication::ShowSplashScreen(void)
  12. {
  13. const short    kProcID = dBoxProc,          // Window Manager window type = 1
  14.                       kPicResID = 2000,    // PICT resource ID
  15.                       kPICTx = 250,            // Width of PICT in pixels
  16.                       kPICTy = 130;            // Height   "
  17. const long        kDuration = 120;                    // Delay for @ 2 secs ( = 120/60 )
  18. CDirector    *myDir = NULL;                        // TCL based object pointers...
  19. CWindow      *myWindow = NULL;
  20. CPicture     *myPicture = NULL;
  21. Rect         aRect = {0, 0, kPICTy, kPICTx};
  22. long         finalTick = 0;
  23.  
  24. myDir = new CDirector(this);                        // Create Bureaucrat & Window
  25. myWindow = new CWindow(&aRect, false, kProcID, false, false, myDir);
  26. myPicture = new CPicture(myWindow, myDir);    // Create CPicture object
  27. myPicture->FitToEnclFrame(true, true);
  28. ::SetRect(&aRect, 2, 2, -2, -2);                // Shrink enclosure by 2 pixels
  29. myPicture->ChangeSize(&aRect, false);
  30. myPicture->UsePICT(kPicResID);                    // Grab PICT from resource
  31. myWindow->MoveOffScreen();                             // Get ready for drawing
  32. myWindow->Select();
  33. myPicture->Prepare();
  34. gDecorator->CenterWindow(myWindow);            // Need window on screen to draw PICT
  35. myPicture->Draw(&aRect);                // Rect param is not really needed
  36. ::Delay(kDuration, &finalTick);                    // Delay long enough for user to read screen
  37. myDir->CloseWind(myWindow);                        // Close window & tidy up memory
  38. TCLForgetObject(myDir);
  39. if (myPicture != NULL)
  40.   TCLForgetObject(myPicture);
  41. }
  42. – Andrew Nemeth, Warrimoo Australia